<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TitleAdd1</title>
</head>
<link href="./layui/css/layui.css" rel="stylesheet">
<body>
<div style="margin: 0 auto;width:70%;display: block">
    <form class="layui-form" action="" >
    <h1 id="show">新增一级标题</h1>
    <div class="layui-form-item">
        <label class="layui-form-label">一级标题章数</label>
        <div class="layui-input-block">
            <input type="text" name="d1"  lay-verify="required|number"  placeholder="请输入数字" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="zwbt" required  placeholder="请输入内容" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <textarea name="zwnr" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo" style="display: none" id="submit">提交</button>
            </div>
        </div>
    </form>
</div>
</body>
</html>
<script src="./js/jquery-1.9.1.min.js"></script>
<script src="./layui/layui.js"></script>

<script>


    layui.use('form', function(){
        var form = layui.form;
        form.on('submit(formDemo)', function(data){
            if (data.field.zwnr){
                zwnr=data.field.zwnr.replace(/\n|\r\n/g,'\\r\\n');
            }
            zwbt=data.field.zwbt;
            d1=data.field.d1;
            localStorage.setItem(d1+"oneadd",zwnr);
            var params={
                zwbt,zwnr,d1,'type':"a1",
            }
            $.ajax({
                type:'post',
                url:'./zwToDB.php',
                data:params,
                success:function (data) {
                    var jsonData = JSON.parse(data);
                    if (jsonData.status){
                        alert(jsonData.msg)
                    }else {
                        alert(jsonData.msg)
                    }
                },
                error:function () {
                    layer.msg("请求异常")
                }
            });

        })
    })

    function submitting() {
        $("#submit").click()
    }



</script>